﻿<UserControl x:Class="FrontEnd.ObjectExplorer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
			 xmlns:fe="clr-namespace:FrontEnd"
			 DataContext="{Binding RelativeSource={RelativeSource Self}}">
	
	<UserControl.CommandBindings>
		<CommandBinding Command="fe:MyCommands.Connect" Executed="Connect" />
		<CommandBinding Command="fe:MyCommands.Attach" Executed="Attach" />
		<CommandBinding Command="fe:MyCommands.Detach" Executed="Detach" />
		<CommandBinding Command="fe:MyCommands.SelectTop" Executed="SelectTop" />
		<CommandBinding Command="fe:MyCommands.ShowCreateSQL" Executed="ShowCreateSQL" />
		<CommandBinding Command="fe:MyCommands.CheckIntegrity" Executed="CheckIntegrity" />
		<CommandBinding Command="fe:MyCommands.Vacuum" Executed="Vacuum" />
	</UserControl.CommandBindings>
	
	<UserControl.Resources>
		<fe:StringToImageConverter x:Key="StringToImageConverter"></fe:StringToImageConverter>
		<fe:NodeTypeToContextMenuConverter x:Key="NodeTypeToContextMenuConverter"></fe:NodeTypeToContextMenuConverter>
	</UserControl.Resources>

	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="auto" />
			<RowDefinition Height="auto" />
			<RowDefinition />
		</Grid.RowDefinitions>

		<StackPanel Background="#9CB6D3">
			<TextBlock Text="Object Explorer" Padding="3" />
		</StackPanel>
		
		<ToolBar ToolBarTray.IsLocked="True" Grid.Row="1">
			<Button Command="fe:MyCommands.Connect">
				<Button.Content>
					<StackPanel Orientation="Horizontal">
						<Image Source="/SQLiter;component/Images/Connect.png" />
						<TextBlock Text="Connect"  Padding="3,0,0,0" />
					</StackPanel>
				</Button.Content>
			</Button>
			<Button Click="Refresh">
				<Button.Content>
					<StackPanel Orientation="Horizontal">
						<Image Source="/SQLiter;component/Images/Refresh.png" />
						<TextBlock Text="Refresh"  Padding="3,0,0,0" />
					</StackPanel>
				</Button.Content>
			</Button>
		</ToolBar>

		<TreeView Name="tvObjects" Padding="0,5,0,0" Grid.Row="2" PreviewMouseDoubleClick="DoubleClick">
			<TreeView.ItemTemplate>
				<HierarchicalDataTemplate ItemsSource="{Binding Nodes}">
					<StackPanel Orientation="Horizontal" Margin="4,3" ContextMenu="{Binding Converter={StaticResource NodeTypeToContextMenuConverter}}">
						<Image Source="{Binding Converter={StaticResource StringToImageConverter}}" />
						<TextBlock Text="{Binding Title}" Padding="4,0,0,0" />
					</StackPanel>
				</HierarchicalDataTemplate>
			</TreeView.ItemTemplate>
		</TreeView>
	</Grid>
</UserControl>
